/**
 * zmn 服务分类-产品分类关联-验收项目
 * @author yangshuangping
 * @since 2021-11-25 09:21:20
 */
var zmnSelect = null;
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate', "zmnSelect"], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    form.render(null, "zmn-form");
    // 初始化下拉组件
    labelSelect.init('engineerAcceptProject', json.listEngineerAcceptProject.length > 0 ? json.listEngineerAcceptProject : null, "/serv/categ/ass/selectListAcceptProject");
    labelSelect.init('userAcceptProject', json.listUserAcceptProject.length > 0 ? json.listUserAcceptProject : null, "/serv/categ/ass/selectListUserAcceptProject");

    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {
        var data = obj.field;
        var url = "/serv/categ/ass/saveAcceptProject.action";
        if (zmnUtil.isEmptyNull(data.engineerAcceptProject)) {
            layer.alert("请选择工程师验收项目!");
            return false;
        }
        if (zmnUtil.isEmptyNull(data.userAcceptProject)) {
            layer.alert("请选择用户验收项目!");
            return false;
        }
        $.ajax({
            async: false,
            type: "POST",
            url: url,
            dataType: "json",
            data: {
                "groupId": data.groupId,
                "engineerAcceptProject": data.engineerAcceptProject,
                "userAcceptProject": data.userAcceptProject
            },
            success: function (result) {
                if (result.status == 200) {
                    parent.reload(result.message);
                    cancel();
                } else {
                    layui.layer.msg(result.message, {"icon": 2});
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        })
        return false;
    });
    //对外暴露的接口
    exports('plat_servAssCategory_acceptproject', {});
});

// 取消
function cancel() {
    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
}